package com.suxin.nio;

import com.firenio.codec.lengthvalue.LengthValueCodec;
import com.firenio.component.*;

/**
 * @author Tang
 * @classname SimpleServer
 * @description [  ]
 * @date 2021/2/5 9:52
 */
public class SimpleServer {

    public static void main(String[] args) throws Exception{

        IoEventHandle eventHandle = new IoEventHandle() {
            @Override
            public void accept(Channel ch, Frame frame) throws Exception {
                String text = frame.getStringContent();
                frame.setContent(ch.allocateWithSkipHeader(1));
                frame.write("yes server already accept your message:",ch);
                frame.write(text, ch);
                ch.writeAndFlush(frame);
            }
        };

        ChannelAcceptor acceptor = new ChannelAcceptor(8300);
        acceptor.addChannelEventListener(new LoggerChannelOpenListener());
        acceptor.setIoEventHandle(eventHandle);
        acceptor.addProtocolCodec(new LengthValueCodec());
        acceptor.bind();

    }

}